/**
 * 设置缓存
 * @param {String} key 缓存的key 
 * @param {*} data 缓存具体内容
 */
export function setStorage(key,data) {
	return new Promise(resolve => {
		wx.setStorage({
			key:key,
			data:data,
			success:(res)=>{
				console.log(res);
				resolve(res)
			},
			fail:(err)=>{
				console.log("setStorage:err",err);
				resolve({
					errno: err.errno || 10000,
					errMsg: err.errMsg
				})
			}
		});
	})
}

/**
 * 获取缓存
 * @param {String} key 缓存的key
 */
export function getStorage(key) {
	return new Promise(resolve => {
		wx.getStorage({
			key: key,
			success:(res)=>{
				console.log(res.data);
				resolve(res.data)
			},
			fail:(err)=>{
				console.log("getStorage:err",err);
				resolve({
					errno: err.errno || 10000,
					errMsg: err.errMsg
				})
			}
		});
	})
}

/**
 * 清除缓存
 * @param {String} key 缓存的key
 */
export function removeStorage(key) {
	return new Promise(resolve => {
		wx.removeStorage({
			key: key,
			success:(res)=>{
				console.log("removeStorage:ok",res);
				resolve(res.data)
			},
			fail:(err)=>{
				console.log("removeStorage:err",err);
				resolve({
					errno: err.errno || 10000,
					errMsg: err.errMsg
				})
			}
		});
	})
}